﻿using CodeSystem.App_Start;
using CodeSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

namespace CodeSystem.Controllers
{
    [App_Start.ApiAttributeEx, BaseAuthorize]
    public class BaseController: ApiController
    {
        /// <summary>
        /// 带有自定义msg的成功消息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        protected virtual IHttpActionResult Success(object data, string msg = null)
        {
            return Json(new ApiResultMd { code = ResponseCode.Success, data = data, msg = msg });
        }
        /// <summary>
        /// 返回失败消息
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        protected virtual IHttpActionResult Fail(string msg)
        {
            return Json(new ApiResultMd { code = ResponseCode.Fail, data = null, msg = msg });
        }
    }
}